<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

function job_url($url_title, $date)
{
	return site_url('job/'.date('Y', strtotime($date)) . '/' . date('m', strtotime($date)) . '/' . date('d', strtotime($date)) . '/' . $url_title);
}
function normalize_url($str) {
$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str);
$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);
$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);
$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str);
$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);
$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);
$str = preg_replace("/(đ)/", 'd', $str);
$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'a', $str);
$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'e', $str);
$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'i', $str);
$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'o', $str);
$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'u', $str);
$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'y', $str);
$str = preg_replace("/(G)/", 'g', $str);
$str = preg_replace("/(Đ)/", 'd', $str);
$str = preg_replace("/(')/", '', $str);
$str = preg_replace("/( - | & | : )/", "-", $str);
$str = str_replace(" ", "-", str_replace("&*#39;","",$str));
return $str;
}

function auto_alias($name)
{
	$result = normalize_url($name);
	return $result;
}

function product_url($title,$id)
{
	$result = '';
	$result = site_url('app/'.$id. '-'.normalize_url($title, $id));
	return $result;
}

function article_url($title,$alias)
{
	$result = site_url(normalize_url($title).'-'.$alias);
	return $result;
}

function categories_url($title)// use for news
{
	$result = '';
	$result = site_url('chuyen-muc/'.normalize_url($title));
	return $result;
}

function category_url($title,$id)
{
	$result = '';
	$result = site_url('ung-dung/'.normalize_url($title,$id));
	return $result;
}

function account_activation_url($email, $key)
{
	return site_url('user/account_activation/key/' . $key . '/email/' . $email);
}

function forgotten_password_url($email, $key)
{
	return site_url('user/forgotten_password/key/' . $key . '/email/' . $email);
}

function post_url($url_title, $date)
{
	return site_url(date('Y', strtotime($date)) . '/' . date('m', strtotime($date)) . '/' . date('d', strtotime($date)) . '/' . $url_title);
}

function archive_url($url)
{
	return site_url('archive/' . $url);
}

function scategory_url($category_name,$url_name)
{
	return site_url($category_name. '/' . $url_name);
}

function tag_url($tag_name)
{
	return site_url('tags/' . $tag_name);
}

function page_url($url_title)
{
	return site_url('pages/' . $url_title);
}

function categoriesx_url($categories, $blank = FALSE)
{
	$categories_count = count($categories);
	
	$i = 0;
	$result = '';
	foreach ($categories as $category)
	{
		if ($blank)
		{
			$result .= anchor('category/' . $category['url_name'], $category['name'], array('target' => '_blank'));
		}
		else
		{
			$result .= anchor('category/' . $category['url_name'], $category['name']);
		}
		
		if ($i < $categories_count - 1)
		{
			$result .= ', ';
		}
		
		$i++;
	}
	
	return $result;
}

/* End of file MY_url_helper.php */
/* Location: ./application/helpers/MY_url_helper.php */